<?php
/*
 * @Author: CHINAKAIYUAN<sunkaiyuan@namenode.cn>
 * @Date: 2022-02-03 00:33:05
 * @LastEditTime: 2023-10-20 13:37:35
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @Description: BOM成品工艺
 */

namespace App\Models;

use App\Traits\MaterialTrait;
use App\Traits\AutoCodeTrait;

class ProPot extends BaseModel
    {
    use MaterialTrait;
    use AutoCodeTrait;
    public $timestamps = true;
    /**
     * 标识
     *
     * @var string
     */
    protected $ACSign = 'INDENT_CODE';
    public $table = "sys_pro_pot";
    public $_auto_resetlot_name = false;
    protected $guarded = [];


    public function loom()
        {
        return $this->belongsTo(Loom::class);
        }
    //生产计划，多个计划可能并缸
    public function pro_plan()
        {
        return $this->hasMany(ProPlan::class, "pro_pot_id");
        }
    public function craft()
        {
        return $this->belongsTo(ProDyecraft::class, "rscode", "code");
        }
    public function endcraft()
        {
        return $this->belongsTo(ProDyecraft::class, "rscodeend", "code");
        }
    //大货
    public function raw()
        {
        return $this->hasMany(ProPotRawDetail::class, "pro_pot_id")->orderBy("sort");
        }
    //染化料出库单
    public function raw_send()
        {
        return $this->hasMany(ProPotRawSend::class, "pro_pot_id")->orderBy("id");
        }
    //版别
    public function revision()
        {
        return $this->belongsTo(ProColorRev::class);
        }
    public function emergency()
        {
        return $this->belongsTo(Dic::class, "emergency_id", "key")->where(function ($q)
            {
            $q->where("code", 'Emergency');
            });
        }
    public function process_pass()
        {
        return $this->hasMany(ProProcessesPass::class, "pro_pot_id");
        }
    public function process()
        {
        return $this->belongsTo(ProProcesses::class);
        }
    public function wip()
        {
        return $this->hasMany(ProProcessesWip::class, "pro_pot_id");
        }
    public function verify()
        {
        return $this->hasMany(ProPotVerify::class, "pro_pot_id");
        }
    public function dyecraft()
        {
        return $this->belongsTo(ProDyecraft::class, "rscode", 'code');
        }
    public function dyeendcraft()
        {
        return $this->belongsTo(ProDyecraft::class, "rscodeend", 'code');
        }
    public function repairreason()
        {
        return $this->belongsTo(ProRepairreasonDetails::class);
        }
    public function repair_msg()
        {
        return $this->belongsTo(QaAbnormalMessage::class);
        }

    public function oqa()
        {
        return $this->hasOne(ProOqa::class);
        }
    }
